<template>
  <div class="order-card" @click="handleClick">
    <div class="card-header">
      <div class="case-no">{{ order.caseNo }}</div>
      <van-tag 
        :type="getStatusType(order.status)" 
        size="medium"
      >
        {{ getStatusText(order.status) }}
      </van-tag>
    </div>
    
    <div class="card-body">
      <div class="device-info">
        <van-icon name="phone-o" class="device-icon" />
        <div class="device-detail">
          <div class="device-model">{{ order.deviceModel }}</div>
          <div class="fault-desc">{{ order.faultDescription }}</div>
        </div>
      </div>
      
      <div class="order-meta">
        <div class="meta-item">
          <van-icon name="clock-o" />
          <span>{{ order.createTime }}</span>
        </div>
        <div v-if="order.serviceCenterName" class="meta-item">
          <van-icon name="location-o" />
          <span>{{ order.serviceCenterName }}</span>
        </div>
      </div>
    </div>
    
    <div v-if="showActions" class="card-footer">
      <van-button 
        size="small" 
        type="primary" 
        plain
        @click.stop="handleViewDetail"
      >
        {{ $t('repair.myOrders.viewDetail') }}
      </van-button>
      <van-button 
        v-if="order.status === 'COMPLETED'"
        size="small" 
        type="default"
        @click.stop="handleSubmitAgain"
      >
        {{ $t('repair.myOrders.submitAgain') }}
      </van-button>
    </div>
  </div>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue'
import { useI18n } from 'vue-i18n'

const { t } = useI18n()

const props = defineProps({
  order: {
    type: Object,
    required: true,
    default: () => ({})
  },
  showActions: {
    type: Boolean,
    default: true
  }
})

const emit = defineEmits(['click', 'view-detail', 'submit-again'])

// 获取状态类型
const getStatusType = (status) => {
  const typeMap = {
    'PENDING': 'warning',
    'ACCEPTED': 'primary',
    'ASSIGNED': 'primary',
    'DEVICE_RECEIVED': 'primary',
    'RECEIVED': 'primary',
    'DETECTING': 'primary',
    'DETECTION_COMPLETED': 'primary',
    'QUOTING': 'primary',
    'QUOTED': 'warning',
    'PAYING': 'warning',
    'PAID': 'success',
    'REPAIRING': 'primary',
    'REPAIR_COMPLETED': 'primary',
    'QUALITY_CHECK': 'primary',
    'QUALITY_CHECKED': 'success',
    'SHIPPING': 'success',
    'SHIPPED': 'success',
    'PICKUP_PENDING': 'success',
    'COMPLETED': 'success',
    'CANCELLED': 'danger'
  }
  return typeMap[status] || 'default'
}

// 获取状态文本
const getStatusText = (status) => {
  return t(`repair.status.${status}`)
}

// 点击卡片
const handleClick = () => {
  emit('click', props.order)
}

// 查看详情
const handleViewDetail = () => {
  emit('view-detail', props.order)
}

// 再次报修
const handleSubmitAgain = () => {
  emit('submit-again', props.order)
}
</script>

<style scoped lang="scss">
.order-card {
  background: #fff;
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  animation: slideIn 0.5s ease-out;
  
  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
    opacity: 0;
    transition: opacity 0.3s;
  }
  
  &:hover::before {
    opacity: 1;
  }
  
  &:active {
    transform: translateY(2px);
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.08);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 2px solid #f7f8fa;
}

.case-no {
  font-size: 16px;
  font-weight: 600;
  color: #323233;
  letter-spacing: 0.5px;
}

.card-body {
  margin-bottom: 14px;
}

.device-info {
  display: flex;
  align-items: flex-start;
  margin-bottom: 14px;
  padding: 12px;
  background: linear-gradient(135deg, #f0f9ff 0%, #f7f8fa 100%);
  border-radius: 10px;
}

.device-icon {
  font-size: 24px;
  color: #1989fa;
  margin-right: 12px;
  flex-shrink: 0;
}

.device-detail {
  flex: 1;
}

.device-model {
  font-size: 15px;
  color: #323233;
  font-weight: 600;
  margin-bottom: 6px;
}

.fault-desc {
  font-size: 13px;
  color: #646566;
  line-height: 1.6;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.order-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.meta-item {
  display: flex;
  align-items: center;
  font-size: 12px;
  color: #969799;
  padding: 4px 8px;
  background: #f7f8fa;
  border-radius: 6px;
  width: fit-content;
  
  .van-icon {
    font-size: 13px;
    margin-right: 6px;
  }
}

.card-footer {
  display: flex;
  gap: 10px;
  padding-top: 14px;
  border-top: 2px solid #f7f8fa;
  
  .van-button {
    flex: 1;
    height: 36px;
    border-radius: 18px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s;
    
    &:active {
      transform: scale(0.96);
    }
  }
}

// 优化 Tag 样式
:deep(.van-tag) {
  padding: 4px 12px;
  border-radius: 12px;
  font-weight: 500;
  font-size: 12px;
}
</style>

